<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>mod_usertrack.so 的扩展安装以及使用 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>mod_usertrack.so 的扩展安装以及使用</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Apache/">Apache</a> <a class="article__tag-link" href="/tags/LAMP/">LAMP</a>
			</span>
		
	</div>

	

	
		<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mod_usertrack.so 是在用户首次来到当前网站的时候给用户种下一个唯一的cookie，这个cookie是用户首次来当前网站的IP地址加上一个随机字符串组成的。用这个IP加随机字符串来标识用户的唯一性。这样就可以区分同一个IP下的不同用户了。</p>
<h2 id="1-mod-usertrack-so-的安装。"><a href="#1-mod-usertrack-so-的安装。" class="headerlink" title="1. mod_usertrack.so 的安装。"></a>1. mod_usertrack.so 的安装。</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;到apache的源码包下，找到 mod_usertrack.c ，默认会在 modules/metadata/ 下，如果找不到find一下。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">/usr/<span class="built_in">local</span>/apache/bin/apxs -i -a -c mod_usertrack.c</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这样就安装好了，安装好后，会自动在 httpd.conf 中增加一行：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">LoadModule usertrack_module   modules/mod_usertrack.so</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;当然了，mod_usertrack.so 同样会安装到  modules/ 下</p>
<h2 id="2-配置httpd-conf-使用-mod-usertrack-so"><a href="#2-配置httpd-conf-使用-mod-usertrack-so" class="headerlink" title="2. 配置httpd.conf 使用 mod_usertrack.so"></a>2. 配置httpd.conf 使用 mod_usertrack.so</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在httpd.conf 中加入：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">CookieTracking on     <span class="comment"># 打开cookietracking 功能</span></div><div class="line">CookieExpires <span class="string">"1 years"</span>  <span class="comment"># 设置cookie失效日期</span></div><div class="line">CookieStyle Cookie      <span class="comment"># 设置cookie的样式</span></div><div class="line">CookieName   12345    <span class="comment"># 自定义，可以不加该选项</span></div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;然后修改日志格式</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">LogFormat <span class="string">"%h %l %u %t \"%r\" %&gt;s %b \"%&#123;Referer&#125;i\" \"%&#123;User-Agent&#125;i\" %&#123;cookie&#125;n"</span> combined</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;其实，就是在默认的日志格式中加入  %{cookie}n </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果，你只想针对某个虚拟主机生效，请把</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">CookieTracking on</div><div class="line">CookieExpires <span class="string">"1 years"</span></div><div class="line">CookieStyle Cookie</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;以上三行加入到相关的虚拟主机配置段中。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;参考：<a href="http://www.chedong.com/blog/archives/001077.html" target="_blank" rel="external">http://www.chedong.com/blog/archives/001077.html</a></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/Apache/16. mod_usertrack.so 的扩展安装以及使用/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
